import Vue from 'vue'
import App from './App.vue'
// 导入组件库
import ElementUI from 'element-ui'
import store from '@/store'
// 导入组件样式
import 'element-ui/lib/theme-chalk/index.css';
import router from './router'
import axios from 'axios'

// 配置ElementUI插件
Vue.use(ElementUI)
Vue.prototype.$http = axios
axios.defaults.baseURL = 'http://192.168.10.1:8086/wm-crm-dev/'
axios.interceptors.request.use(config=>{
  var token = sessionStorage.getItem('token')
  config.headers['Authorization'] = token
  return config
},error=>{
  return Promise.reject(error)
})


router.beforeEach((to, from, next) => {
  const username = sessionStorage.getItem('username')
  if (to.name !== 'Login' && !username) next({ name: 'Login' })
  // 如果用户未能验证身份，则 `next` 会被调用两次
  next()
})


Vue.config.productionTip = false

new Vue({
  router,
  store,
  render: h => h(App),
}).$mount('#app')
